﻿using DayuCode.Designer.Entity;
using DayuCode.Designer.Service;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DayuCode.Designer.Forms
{
    public partial class FormProjectCatalog : UIForm
    {
        ProjectCatalog catalog;
        public FormProjectCatalog(ProjectCatalog catalog)
        {
            InitializeComponent();
            this.catalog = catalog;
            if(this.catalog == null)
            {
                throw new Exception("catalog不能为空");
            }
            txtName.Text = catalog.Name;
            txtOrdnum.Text = "" + catalog.Ordnum;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            string name = txtName.Text.Trim();

            int ordnum = 0;
            string ordnumStr = txtOrdnum.Text.Trim();
            if (!string.IsNullOrEmpty(ordnumStr))
            {
                ordnum = int.Parse(ordnumStr);
            }

            if (string.IsNullOrEmpty(name))
            {
                ShowErrorTip("名称不能为空");
                return;
            }
            catalog.Name = name;
            catalog.Ordnum = ordnum;
            catalog = ProjectCatalogHandler.saveProjectCatalog(catalog);
            this.Close();
            this.DialogResult = DialogResult.OK;
        }

        public ProjectCatalog ProjectCatalog
        {
            get { return catalog; }
        }
    }
}
